import { routerRedux } from 'dva/router'
import { parse } from 'qs'
import config from 'config'
import { EnumRoleType } from 'enums'
import { query } from 'services/borrow'

const { prefix } = config

export default {
	namespace:'archivalReminders',
	state:{
		list:'',
		pagination1: {
	      showSizeChanger: true,
	      showQuickJumper: true,
	      showTotal: total => `共 ${total} 条`,
	      current: 1,
	      total: null
	    },		
	},
	subscriptions:{
	    setup({ dispatch, history }) {
	      // history.listen(location => {
	      //   if ( location.pathname === "/borrowManager/archivalReminders" ) {
	      //     dispatch({
	      //       type: "query",
	      //       payload: { page: 1, pageSize: 10, operatingType: 2 }
	      //     });
	      //   }
	      // });
	    }		
	},
	effects:{
		*query({payload},{call,put}){
			const data = yield call(query,payload)
			if(data){
				yield put({
					type:'querySuccess',
					payload:{
						list: data.page.list,
			            pagination1: {
			              total: data.page.totalCount,
			              current: data.page.currPage
			            }
					}
				})
			}
		}
	},
	reducers:{
	  querySuccess(state,action) {
	  	const { list,pagination1 } = action.payload
	  	return{
	  		...state,
	  		list,
	  		pagination1: {
	          ...state.pagination1,
	          ...pagination1
	        },
	  	}
	  }
    },
}
